﻿$.locationSelect = function (province, city) {
    var jsonCache;

    var provinceSel = $("#" + province);
    var citySel = $("#" + city);

    provinceSel.change(function () {
        citySel.empty();
        var id = provinceSel.val();

        for (var i = 0; i < jsonCache.city.length; i++) {
            if (id.substring(0, 2) == jsonCache.city[i].id.substring(0, 2)) {
                citySel.append("<option value='" + jsonCache.city[i].id + "'>" + jsonCache.city[i].text + "</option>");
            }
        }
    });

    $.getJSON("/scripts/area.js",
        function (data) {
            jsonCache = data;
            for (var i = 0; i < jsonCache.province.length; i++) {
                provinceSel.append("<option value='" + jsonCache.province[i].id + "'>" + jsonCache.province[i].text + "</option>");
            }
            provinceSel.change();
        }
    );
}